{% from pyquery import PyQuery %}
{% import ast %}


{% if fully %}
<article class="media box">
    <figure class="media-left">
        <p class="image is-48x48">
            <img src="{{ broadcast.user.avatar if broadcast.user else 'https://img1.doubanio.com/icon/user_normal.jpg' }}">
        </p>
    </figure>
    <div class="media-content">
        <div class="content">
{% else %}
<article class="content box">
{% end %}

<p>
{% if broadcast.user %}
    <strong><a href="{{ reverse_url('user', broadcast.user.douban_id) }}">{{ broadcast.user.name }}</a></strong>
    {% if broadcast.status_url %}
    <a href="{{ broadcast.status_url }}" title="访问广播的豆瓣网页" class="external-link">
        <span class="icon">
            <i class="fas fa-external-link-alt"></i>
        </span>
    </a>
    {% end %}
{% else %}
    <strong>未知用户</strong>
{% end %}
<span>
{% if broadcast.target_type == 'sns' %}
说：
{% elif broadcast.target_type == 'movie' %}
看电影：
{% elif broadcast.target_type == 'music' %}
听音乐：
{% elif broadcast.target_type == 'book' %}
读书：
{% elif broadcast.target_type == 'rec' %}
分享：
{% elif broadcast.target_type == 'fav' %}
喜欢：
{% elif broadcast.target_type == 'site' %}
小站：
{% elif broadcast.target_type == 'doulist' %}
添加豆列：
{% elif broadcast.target_type == 'game' %}
玩游戏：
{% elif broadcast.target_type == 'loc' %}
参加活动：
{% elif broadcast.target_type == 'ark' %}
写评论：
{% elif broadcast.target_type == 'arya' %}
赞赏：
{% elif broadcast.target_type == '' %}
转播：
{% else %}
其他：
{% end %}
</span>
</p>
{% if broadcast.blockquote %}
<p class="text-break">{{ PyQuery(broadcast.blockquote).text() }}</p>
{% end %}

{% if broadcast.is_reshared %}
    {% if broadcast.reshared %}
        {% module Template('my/_broadcast.html', fully=False, broadcast=broadcast.reshared) %}
    {% else %}
    <article class="content box">
        <p>该广播已被<del>作者</del>管理员删除</p>
    </article>
    {% end %}
{% elif broadcast.target_type == 'sns' and broadcast.object_kind == '1018' %}
    {% if broadcast.attachments %}
        {% set attachments = ast.literal_eval(broadcast.attachments) %}
        {% for attachment in attachments %}
            {% if attachment['type'] == 'image' %}
                <figure class="image is-128x128" style="overflow: hidden; display: inline-block;">
                    <a href="#" class="preview action-open" data-target="#modal-preview"><img class="load-from-cache" data-src="{{ attachment['url'] }}"></a>
                </figure>
            {% end %}
        {% end %}
    {% end %}
{% elif broadcast.target_type == 'rec' %}
    {% set rec = PyQuery(broadcast.content).find('.status-item>.mod>.bd.rec>.block') %}
    {% set rec_video = PyQuery(broadcast.content).find('.status-item>.mod>.bd.rec>.block-video') %}
    {% if rec %}
    <article class="box media">
        {% set rec_img = PyQuery(PyQuery(PyQuery(rec).find('.pic img').eq(0))) %}
        {% if rec_img %}
        <figure class="media-left is-marginless">
            <p class="image is-64x64" style="overflow: hidden;">
                <img src="{{ rec_img.attr('src') }}">
            </p>
        </figure>
        {% end %}
        <div class="media-content" style="margin-left: 0.75rem;">
            <div class="content">
                {% set rec_title = PyQuery(PyQuery(rec).find('.content>.title>a')) %}
                <p class="is-size-5"><a href="{{ rec_title.attr('href') }}" class="external-link">{{ rec_title.text() }}</a></p>
                
                {% set rec_abstract = PyQuery(PyQuery(rec).find('.content>p').eq(0)) %}
                <p class="text-break">{{ rec_abstract.text() }}</p>
            </div>
        </div>
    </article>
    {% elif rec_video %}
    <article class="box content">
        {% set rec_img = PyQuery(PyQuery(PyQuery(rec_video).find('.video-player img').eq(0))) %}
        {% set rec_title = PyQuery(PyQuery(PyQuery(rec_video).find('.title>a').eq(0))) %}
        <figure style="text-align: left;">
            <p class="image" style="overflow: hidden; max-width: 480px;">
                <img src="{{ rec_img.attr('src') }}">
            </p>
            <p class="is-size-5"><a href="{{ rec_title.attr('href') }}">{{ rec_title.text() }}</a></p>
        </figure>
    </article>
    {% else %}
    <blockquote class="text-break">{{ PyQuery(broadcast.content).text() }}</blockquote>
    {% end %}
{% elif broadcast.target_type == 'movie' and broadcast.object_kind == '1002' %}
    {% module Movie(broadcast.object_id) %}
{% elif broadcast.target_type == 'book' and broadcast.object_kind == '1001' %}
    {% module Book(broadcast.object_id) %}
{% elif broadcast.target_type == 'music' and broadcast.object_kind == '1002' %}
    {% module Music(broadcast.object_id) %}
{% else %}
    <blockquote class="text-break">{{ PyQuery(broadcast.content).text() }}</blockquote>
{% end %}

{% if not broadcast.is_noreply %}
<nav class="level">
    <div class="level-left">
        <div class="level-item">{{ broadcast.comments_count }}回应</div>
        <div class="level-item">赞({{ broadcast.like_count }})</div>
        <div class="level-item">转播({{ broadcast.reshared_count }})</div>
        {% if not fully %}
        <div class="level-item"><a href="{{ reverse_url('broadcast', broadcast.douban_id) }}">查看详情</a></div>
        {% end %}
    </div>
    <div class="level-right">
        <div class="level-item">{{ broadcast.created if broadcast.created else '' }}</div>
    </div>
</nav>
{% end %}


{% if fully %}
        </div>
    </div>
    <div class="media-right">
        <ul class="menu has-text-centered">
            <li><a href="{{ reverse_url('broadcast', broadcast.douban_id) }}" class="button">查看详情</a></li>
        </ul>
    </div>
</article>
{% else %}
</article>
{% end %}
